﻿
using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.deepprocessing
{
    public class DeepprocessingLotHandler : IRequestHandler<DeepprocessingLotCommond, Rulst>
    {


        private readonly IbaseRpository<ProcessMess> _ProcessMess;

        public DeepprocessingLotHandler(IbaseRpository<ProcessMess> processMess)
        {
            _ProcessMess = processMess;
        }
        public async Task<Rulst> Handle(DeepprocessingLotCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };
            var list = _ProcessMess.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid).FirstOrDefault();

            if (list != null)
            {


                list.ProcessLot = request.ProcessLot;

                _ProcessMess.update(list);
                query.Code = 1;
                query.MSG = "修改成功";
            }
            else
            {

                var query1 = new ProcessMess()
                {

                    ProcessLot = request.ProcessLot,
                    ProDuctionBasicid = request.ProDuctionBasicid
                    ,
                    ProcessBossName="",
                    Processclass="",
                    Processid=0,
                    Processlicence="",
                    ProcessPersonincharge="",
                };
                _ProcessMess.Add(query1);
                query.Code = 1;
                query.MSG = "添加成功";
            }


            return query;




        }
    }
}
